package com.mysqldemo.enums;

public enum ResponseCodeEnum {
    SUCCESS(200,"成功"),
    ERROR(500,"失败"),
    PARAM_ERROR(400,"参数错误"),
    NOT_FOUND(404,"资源不存在"),
    NOT_LOGIN(401,"未登录"),
    NOT_AUTH(403,"未授权"),
    NOT_SUPPORTED(405,"不支持该方法"),
    INTERNAL_SERVER_ERROR(500,"服务器内部错误"),
    SERVER_BUSY(503,"服务器正忙，请稍后再试"),
    PRIMARY_KEY_CONFLICT(601,"主键冲突"),
    DATA_NOT_EXIST(602,"数据不存在");
    private Integer code;
    private String message;

    ResponseCodeEnum(Integer code,String message){
        this.code = code;
        this.message = message;
    }

    public static ResponseCodeEnum getEnumByCode(Integer code){
        for (ResponseCodeEnum responseCodeEnum : ResponseCodeEnum.values()) {
            if (responseCodeEnum.getCode().equals(code)){
                return responseCodeEnum;
            }
        }
        return null;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

}
